package com.example.moblie2030606150cjk0408;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMianTitle;
    private CheckBox ChkboxMainYinqing;
    private CheckBox ChkboxMainFangxiangpan;
    private CheckBox ChkboxMainBoli;
    private Button BtnMainBuy;
    private TextView tvMainTip;
    private TextView tvMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        ChkboxMainYinqing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    tvMainResult.setText(buttonView.getText().toString());
                }else {
                    tvMainResult.setText(null);
                }
            }
        });
        ChkboxMainBoli.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    tvMainResult.setText(buttonView.getText().toString());
                }else {
                    tvMainResult.setText(null);
                }
            }
        });
        ChkboxMainFangxiangpan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    tvMainResult.setText(buttonView.getText().toString());
                }else {
                    tvMainResult.setText(null);
                }
            }
        });
        BtnMainBuy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ChkboxMainYinqing.isChecked()) {
                    Toast.makeText(MainActivity.this,ChkboxMainYinqing.getText().toString(),Toast.LENGTH_SHORT).show();
                }
                if (ChkboxMainBoli.isChecked()) {
                    Toast.makeText(MainActivity.this,ChkboxMainBoli.getText().toString(),Toast.LENGTH_SHORT).show();
                }
                if (ChkboxMainFangxiangpan.isChecked()) {
                    Toast.makeText(MainActivity.this,ChkboxMainFangxiangpan.getText().toString(),Toast.LENGTH_SHORT).show();
                }
                tvMainResult.setText(null);
            }
        });
    }

    private void initView() {
        tvMianTitle = (TextView) findViewById(R.id.tv_mian_title);
        ChkboxMainYinqing = (CheckBox) findViewById(R.id.Chkbox_main_yinqing);
        ChkboxMainFangxiangpan = (CheckBox) findViewById(R.id.Chkbox_main_fangxiangpan);
        ChkboxMainBoli = (CheckBox) findViewById(R.id.Chkbox_main_boli);
        BtnMainBuy = (Button) findViewById(R.id.Btn_main_buy);
        tvMainTip = (TextView) findViewById(R.id.tv_main_tip);
        tvMainResult = (TextView) findViewById(R.id.tv_main_result);
    }
}
